home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Programming / XMPlayer-library / Examples / C / example.c
Encoding:
C/C++ Source or Header  |  2001-04-17  |  4.2 KB  |  146 lines

  1. /*           This program explains how to use xmplayer.library      */
  2. /*                           Author: Igor/TCG                       */
  3. /*                           Date: 17.04.2001                       */
  4. /*             Written especially for CruST/Amnesty^.humbug.        */
  5.  
  6. /*
  7. **    Library coded by CruST / Amnesty^.humbug.
  8. **    Released by .humbug. 17.04.2001
  9. **
  10. **    Library based on the PS3M source 
  11. **    Copyright (c) Jarno Paananen a.k.a. Guru / S2 1994-96.
  12. */
  13.  
  14. /********************************************************************/
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <exec/types.h>
  18. #include <exec/exec.h>
  19. #include <proto/exec.h>
  20. #include <dos/dos.h>
  21. #include <proto/dos.h>
  22. #include <libraries/xmplayer.h>
  23. #include <proto/xmplayer.h>
  24.  
  25. /********************************************************************/
  26. struct ReqToolsBase *ReqToolsBase = NULL;
  27. struct DosLibrary *DOSBase = NULL;
  28. struct Library *XMPlayerBase = NULL;
  29.  
  30. char *prname        = "Amnesty XM-Player";            /* process name */
  31. char *exampleXM    = "PROGDIR:example.xm";            /* path to module file */
  32.  
  33. /********************************************************************/
  34. void StartCode(void);
  35. void EndCode(void);
  36. APTR LoadData(char *filename, ULONG memtype);
  37.  
  38. /********************************************************************/
  39. int main()
  40. {
  41.     struct XMPlayerInfo *XMPlayerInfo = NULL;
  42.     APTR buffer = NULL;
  43.  
  44.     StartCode();                                        /* open libs, load data */
  45.  
  46.     /* load module into memory */
  47.     if( (buffer = LoadData(exampleXM,MEMF_ANY)) == NULL)
  48.     {
  49.         printf("Can't open %s\nThist means that is out of memory (to much cholesterol!)\nor the file was lost (to much polish vodka!)\n",exampleXM);
  50.         EndCode();
  51.         exit(10);
  52.     }
  53.  
  54.     /* allocate and init XMPlayerInfo structure */
  55.     if( (XMPlayerInfo = AllocVec(sizeof(struct XMPlayerInfo),MEMF_ANY)) == NULL)
  56.     {
  57.         printf("Out of memory... to much russian vodka!\n");
  58.         EndCode();
  59.         exit(10);
  60.     }
  61.     
  62.     XMPlayerInfo->XMPl_Cont = buffer;                        /* module pointer */
  63.     XMPlayerInfo->XMPl_Mixtype = XM_STEREO14;                /* mixing type; see autodoc */
  64.     XMPlayerInfo->XMPl_Mixfreq = 22000;                        /* mixing frequency; see autodoc */
  65.     XMPlayerInfo->XMPl_Vboost = 2;                            /* volume boosting; see autodoc */
  66.     XMPlayerInfo->XMPl_PrName = prname;                        /* name for playing process; see autodoc */
  67.     XMPlayerInfo->XMPl_PrPri = 0;                                /* playing process priority; see autodoc */
  68.  
  69.     if( XMPl_Init(XMPlayerInfo) == TRUE )                    /* inits a player structure */
  70.     {
  71.         XMPl_Play();                                                /* I don't know... ;) */
  72.         printf("playing xm module... press enter to stop...\n");
  73.  
  74.         getchar();                                                    /* wait user reaction ;) */
  75.         XMPl_StopPlay();                                            /* stop playing process */
  76.  
  77.         XMPl_DeInit();                                                /* well... guess what ;) */
  78.     }
  79.     else
  80.         printf("Houston! We have a problem... Init fails\n");
  81.     
  82.     if(XMPlayerInfo != NULL)                                    /* and free resources */
  83.         FreeVec(XMPlayerInfo);
  84.     
  85.     if(buffer != NULL)
  86.         FreeVec(buffer);
  87.  
  88.     EndCode();
  89.     return 0;
  90. }
  91.  
  92. /********************************************************************/
  93. void StartCode()
  94. {
  95.     if( (DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",0)) == NULL)
  96.     {
  97.         printf("Ooops... turn off your girl friend, call your local customer service and pray... I can't open dos.library...\n");
  98.         EndCode();
  99.         exit(666);                                                    /* ;-))))) */
  100.     }
  101.  
  102.     if( (XMPlayerBase = OpenLibrary("xmplayer.library",1)) == NULL )
  103.     {
  104.         printf("Can't open xmplayer.library - throw away your computer and start singing...\n");
  105.         EndCode();
  106.         exit(10);
  107.     }
  108. }
  109.  
  110. /********************************************************************/
  111. void EndCode()
  112. {
  113.     if(DOSBase != NULL)
  114.         CloseLibrary((struct Library *)DOSBase);
  115.  
  116.     if(XMPlayerBase != NULL)
  117.         CloseLibrary(XMPlayerBase);
  118. }
  119.  
  120. /********************************************************************/
  121. APTR LoadData(char *filename, ULONG memtype)
  122. {
  123.     BPTR lock;
  124.     BPTR file;
  125.     APTR buffer = NULL;
  126.  
  127.     struct FileInfoBlock fib;
  128.  
  129.     if( (lock = Lock(filename,ACCESS_READ)) )
  130.     {
  131.         Examine(lock,&fib);
  132.  
  133.         if( (buffer = AllocVec(fib.fib_Size,memtype)) )
  134.         {
  135.             if( (file = OpenFromLock(lock)) )
  136.             {
  137.                 Read(file,buffer,fib.fib_Size);
  138.                 Close(file);
  139.             } else {FreeVec(buffer);buffer = NULL;}
  140.         } else {UnLock(lock);}
  141.     }
  142.     return buffer;
  143. }
  144.  
  145. /********************************************************************/
  146.